// index.js
// 获取应用实例
const app = getApp()
var util = require('../../utils/util')
var api = require('../../config/api')
Page({
  data: {
    cartForm:[
      {id:"1",name:"工作日",type:1,fromtarget:'10:30',fromhome:'10:45'},
      {id:"2",name:"工作日",type:1,fromtarget:'11:00',fromhome:'11:15'},
      {id:"3",name:"工作日",type:1,fromtarget:'11:30',fromhome:'11:45'},
      {id:"4",name:"工作日",type:1,fromtarget:'12:00',fromhome:'14:15'},
      {id:"5",name:"工作日",type:1,fromtarget:'14:30',fromhome:'14:15'},
      {id:"6",name:"工作日",type:1,fromtarget:'15:00',fromhome:'15:15'},
      {id:"7",name:"工作日",type:1,fromtarget:'15:30',fromhome:'15:45'},
      {id:"8",name:"工作日",type:1,fromtarget:'16:00',fromhome:'16:15'},
      {id:"9",name:"节假日",type:2,fromtarget:'10:00',fromhome:'10:15'},
      {id:"10",name:"节假日",type:2,fromtarget:'10:30',fromhome:'10:45'},
      {id:"11",name:"节假日",type:2,fromtarget:'11:00',fromhome:'11:15'},
      {id:"12",name:"节假日",type:2,fromtarget:'11:30',fromhome:'11:45'},
      {id:"13",name:"节假日",type:2,fromtarget:'12:00',fromhome:'12:15'},
      {id:"14",name:"节假日",type:2,fromtarget:'12:30',fromhome:'12:45'},
      {id:"15",name:"节假日",type:2,fromtarget:'13:00',fromhome:'13:15'},
      {id:"16",name:"节假日",type:2,fromtarget:'14:00',fromhome:'14:15'},
      {id:"17",name:"节假日",type:2,fromtarget:'14:30',fromhome:'14:45'},
      {id:"18",name:"节假日",type:2,fromtarget:'15:00',fromhome:'15:15'},
      {id:"19",name:"节假日",type:2,fromtarget:'15:30',fromhome:'15:45'},
      {id:"20",name:"节假日",type:2,fromtarget:'16:00',fromhome:'16:15'},
      {id:"21",name:"节假日",type:2,fromtarget:'16:30',fromhome:'16:45'},
      {id:"22",name:"节假日",type:2,fromtarget:'17:00',fromhome:'17:15'},
      {id:"23",name:"节假日",type:2,fromtarget:'17:30',fromhome:'17:45'},
      {id:"24",name:"节假日",type:2,fromtarget:'18:00',fromhome:'18:15'},
      {id:"25",name:"节假日",type:2,fromtarget:'18:30',fromhome:'18:45'},
      {id:"26",name:"节假日",type:2,fromtarget:'19:00',fromhome:'19:15'},
      {id:"27",name:"节假日",type:2,fromtarget:'19:30',fromhome:'19:45'},
      {id:"28",name:"节假日",type:2,fromtarget:'20:00',fromhome:'20:15'}
    
    ],
    banners: [],
    examples: [],
    categorys: [],
    news: [{
      id: 1,
      content: "时代倾城最棒，不接受反驳......"
    }],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    like: 0
  },
  // 事件处理函数
  bindViewTap() {

  },
  onLoad() {
    this.getBanner();
    this.getCategorys();
    this.getExamples();
    // this.getNews();
  },
  getBanner() {
    let that = this;
    util.request(api.bannerList).then(function (res) {
      that.setData({
        banners: res.data.records
      });
    });

  },
  getCategorys() {
    let that = this;
    util.request(api.categoryList).then(function (res) {
      that.setData({
        categorys: res.data.records
      });
    })
  },
  getExamples() {
    let that = this;
    util.request(api.examples).then(function (res) {
      console.log(res.data.records)
      that.setData({
        examples: res.data.records
      });
    })
  },
  getNews: function () {
    let that = this;
    util.request(api.newsList).then(function (res) {
      console.log(res.data.records, "news")
      that.setData({
        news: res.data.records
      });
    });
  },
  getUserInfo(e) {},
  likeit(e) {
    let examples = this.data.examples;
    var prdid=e.currentTarget.dataset.prdid;
    var tosell=e.currentTarget.dataset.tosell;
    examples.map(item => {
      if (item.id === prdid) {
        item.like = true;
        item.productToSell++;
      }
      return item;
    })
    this.setData({
      examples
    })
    util.request(api.exampleUpdate,{ id:prdid,productToSell:tosell+1},"POST");
  }
})